# -*- coding: utf-8 -*-
from django.db.models import Q
from rest_framework import serializers

from app.emergency.models import DevicePlan
from dvadmin.utils.json_response import SuccessResponse
from dvadmin.utils.serializers import CustomModelSerializer
from dvadmin.utils.viewset import CustomModelViewSet


class DevicePlanSerializer(CustomModelSerializer):
    """
    预案设备控制项-序列化器
    """
    device_name = serializers.CharField(source='device.alia', read_only=True)
    areaplan_name = serializers.CharField(source='areaplan.name', read_only=True)
    class Meta:
        model = DevicePlan
        fields = "__all__"
        read_only_fields = ["id"]


class DevicePlanCreateUpdateSerializer(CustomModelSerializer):
    """
    操作预案设备控制项  创建/更新时的列化器
    """

    class Meta:
        model = DevicePlan
        fields = '__all__'


class DevicePlanViewSet(CustomModelViewSet):
    """
    预案设备控制项接口
    list:查询
    create:新增
    update:修改
    retrieve:单例
    destroy:删除
    """
    queryset = DevicePlan.objects.order_by('-create_datetime')
    serializer_class = DevicePlanSerializer


